// Copyright (c) 2024, the WwMusic project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

package com.springfairy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.springfairy.dao.MoodPointImageMapper;
import com.springfairy.model.MoodPointImages;
import com.springfairy.service.MoodPointImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class MoodPointImageServiceImpl implements MoodPointImageService {
    @Autowired
    private MoodPointImageMapper mapper;

    @Override
    public MoodPointImages uploadImage(int pointId, String imageUrl) {
        MoodPointImages moodPointImages = new MoodPointImages();
        moodPointImages.setFlag(1);
        moodPointImages.setImageUrl(imageUrl);
        moodPointImages.setPointId(pointId);
        moodPointImages.setUploadedAt(new Timestamp(System.currentTimeMillis()));

        mapper.insert(moodPointImages);
        return moodPointImages;
    }

    @Override
    public List<MoodPointImages> getImagesByPoint(int pointId) {
        LambdaQueryWrapper<MoodPointImages> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(MoodPointImages::getPointId,pointId);

        return mapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public boolean deleteImage(int id) {
        return mapper.deleteById(id) > 1;
    }
}
